<template>
  <view>
    <c-navBar title="充值"></c-navBar>
    <view>
      <CForm
        :formRules="formRules"
        @submit="submit"
        v-model:formData="formData"
        :formList="formList"
      ></CForm>
    </view>
  </view>
</template>

<script setup>
import { ref } from "vue"
import CForm from "@/components/CForm/CForm.vue"
import { rechargeSchool } from "@/apis/school"
import { onLoad, onUnload, onBackPress } from "@dcloudio/uni-app"
import { rechargeForm } from "./data"

const { formField, formList, formRules } = rechargeForm
const defaultData = JSON.parse(JSON.stringify(formField))
let formData = ref(JSON.parse(JSON.stringify(formField)))
let schoolId = ""
onLoad((options) => {
  schoolId = options.schoolId
})
onBackPress(() => {
  formData.value = JSON.parse(JSON.stringify(defaultData))
})
const submit = () => {
  rechargeSchool({
    ...formData.value,
    school_id: schoolId
  }).then((res) => {
    if (res.code === 1) {
      uni.showSuccessToast("充值成功！")
      setTimeout(() => {
        uni.navigateBack({
          delta: 1
        })
      }, 1500)
    }
  })
}
</script>

<style lang="scss"></style>
